package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有护理等级
     */
    @Override
    public List<NursingLevelVo> queryAllNursingLevel() {
        List<NursingLevelVo> list = nursingLevelMapper.queryAllNursingLevel();
        return list;
    }

    /**
     * 新增护理等级
     */
    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto,NursingLevel.class);
        nursingLevelMapper.addNursingLevel(nursingLevel);
    }

    /**
     * 条件分页查询护理等级
     */
    @Override
    public PageResponse<NursingLevelVo> PageQuery(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);

        Page<NursingLevelVo> page = nursingLevelMapper.PageQuery(name,status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>(page);

        pageResponse.setRecords(page.getResult());

        return pageResponse;
    }

    /**
     * 根据id查询护理等级
     */
    @Override
    public NursingLevelVo getById(Integer id) {
        return nursingLevelMapper.getById(id);
    }

    /**
     * 修改护理等级
     */
    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {

        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto,NursingLevel.class);

        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    /**
     * 删除护理等级
     */
    @Override
    public void deleteNursingLevel(Integer id) {
        nursingLevelMapper.deleteNursingLevel(id);
    }

    /**
     * 护理等级启用或禁用
     */
    @Override
    public boolean enableOrDisable(Integer id, Integer status) {
        // 查询计划是否存在
        NursingLevelVo nursingLevelVo  = nursingLevelMapper.getById(id);
        if (nursingLevelVo == null) {
            return false;
        }
        nursingLevelMapper.updateStatus(id, status);
        return true;
    }
}
